package comcksys.authserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import comcksys.authserver.entity.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: yxzhang23
 * @time: 2021/4/8
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 通过用户名获取用户信息(包含权限信息)
     * @param username  用户名
     * @return  用户信息 + 权限信息
     */
    @Select("select * from user u where u.username = #{username}")
    @Results(id = "userWithRoles", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "uuid", property = "uuid"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "nick_name", property = "nickName"),
            @Result(column = "id", property = "roles", javaType = List.class,
                    many = @Many(select = "comcksys.authserver.mapper.RoleMapper.getRoleListByUserId"))
    })
    User getUserByUsername(String username);

}
